package demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {
    public static final String[] Cardsuit = {"♥","♠","♣","♦"};
    public static List<Card> BuyCard(){
        List<Card> cardList = new ArrayList<>(52);
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13 ; j++) {
                String suit = Cardsuit[i];
                int rank = j;
                Card card = new Card(rank,suit);
                cardList.add(card);
            }
        }
        return cardList;
    }
    private static void swap(List<Card> deck,int i,int j){
        Card t = deck.get(i);
        deck.set(i,deck.get(j));
        deck.set(j,t);
    }
    private static void shuffle(List<Card> deck){
        Random random = new Random();
        for(int i=deck.size()-1;i>0;i--){
            int j = random.nextInt(i);
            swap(deck,i,j);
        }
    }

    public static void main(String[] args) {
        List<Card> deck = BuyCard();
        System.out.println(deck);
        shuffle(deck);
        System.out.println(deck);

        List <List<Card>> hands = new ArrayList<>();//相当于一个二维数组
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hands.get(j).add(deck.remove(0));
            }
        }
    }
}
